{% extends 'base.html' %}

{% block title %}用户管理{% endblock %}

{% block content %}
<div class="container mt-5">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header bg-primary text-white d-flex justify-content-between align-items-center">
                    <h2>用户管理</h2>
                    <a href="{{ url_for('add_user') }}" class="btn btn-light">添加用户</a>
                </div>
                <div class="card-body">
                    <table class="table table-bordered table-hover">
                        <thead class="table-dark">
                            <tr>
                                <th>ID</th>
                                <th>用户名</th>
                                <th>邮箱</th>
                                <th>是否管理员</th>
                                <th>创建时间</th>
                                <th>最后登录时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for user in users %}
                            <tr>
                                <td>{{ user.id }}</td>
                                <td>{{ user.username }}</td>
                                <td>{{ user.email if user.email else '-' }}</td>
                                <td>{{ '是' if user.is_admin else '否' }}</td>
                                <td>{{ user.created_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                                <td>{{ user.last_login.strftime('%Y-%m-%d %H:%M:%S') if user.last_login else '-' }}</td>
                                <td>
                                    {% if user.id != session['user_id'] %}
                                        <a href="{{ url_for('delete_user', user_id=user.id) }}" class="btn btn-danger btn-sm" onclick="return confirm('确定要删除吗？')">删除</a>
                                    {% else %}
                                        <button class="btn btn-danger btn-sm" disabled>删除</button>
                                    {% endif %}
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}